/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.just.dusin.ooii.database;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Administrator
 */
public class Sumof5minhouroutDao {
    private Connection conn;

    public Sumof5minhouroutDao(Connection conn) {
        this.conn = conn;
    }

   
    public boolean doCreate(DataOf5mBean d5m) throws Exception {
        boolean flag = false;
        PreparedStatement pstmt = null;
        String sql = "INSERT INTO [sumof5minhourout]([orgcode],[year],[month],[day],[hour],[min],[sumof5min],[status])"
                        + " VALUES (?,?,?,?,?,?,?,?)";
        try {
                pstmt = this.conn.prepareStatement(sql);

                pstmt.setString(1, d5m.getMineCode());			
                pstmt.setInt(2, d5m.getYear());
                pstmt.setByte(3, d5m.getMonth());
                pstmt.setByte(4, d5m.getDay());
                pstmt.setByte(5, d5m.getHour());
                pstmt.setByte(6, d5m.getMin());
                pstmt.setDouble(7, d5m.getSumof5min());
                pstmt.setByte(8, (byte)1);

                int len = pstmt.executeUpdate();
                if (len > 0) {
                        flag = true;
                }
        } catch (Exception e) {
                throw e;
        } finally {
                try {
                        pstmt.close();
                } catch (Exception e) {
                        throw e;
                }
        }
        return flag;
    }

    public boolean isExist(String orgCode,int year,int month,int day,int hour,int min) throws Exception {
        
            PreparedStatement pstmt = null;
            String sql = "select * FROM sumof5minhourout WHERE   orgCode=? and year=? and month=? and day=? and hour=? and min=? ";
            try {
                    pstmt = this.conn.prepareStatement(sql);
                    pstmt.setString(1, orgCode);
                    pstmt.setInt(2, year);
                    pstmt.setInt(3, month);
                    pstmt.setInt(4, day);
                    pstmt.setInt(5, hour);
                    pstmt.setInt(6, min);                    
                    ResultSet rs = pstmt.executeQuery();
                    if(rs.next())
                        return true;
                    else
                        return false;
                    
            } catch (Exception e) {
                    throw e;
            } finally {
                    try {
                            pstmt.close();
                    } catch (Exception e) {
                            throw e;
                    }
            }          
    }
    
    public boolean doUpdate(DataOf5mBean d5m) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   
    public boolean doDeleteById(long[] pids) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   
    public DataOf5mBean findById(long pid) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   
    
    public int getTotalSize() {
        return 0;
    }
    
}
